package com.hjm.mall.api;

import com.hjm.mall.api.vo.StoreListVO;
import com.hjm.mall.entity.Store;
import com.hjm.mall.service.impl.StoreServiceImpl;
import com.hjm.mall.util.Result;
import com.hjm.mall.util.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@ResponseBody
@RequestMapping("/api/store")
@Api(value = "image",tags = "哈基米商城——店铺接口")
public class StoreController {

    @Autowired
    StoreServiceImpl storeService;

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查找店铺", notes = "返回json")
    public Result<String> getStoreById(
            @ApiParam("店铺id")
            @PathVariable("id")
                    Integer id){
        Store store = storeService.getStoreById(id);
        if (store == null) {
            // 如果找不到图片，返回一个404响应
            return ResultGenerator.genErrorResult(404,"找不到店铺");
        }
        return ResultGenerator.genSuccessResult(store);
    }
    @GetMapping("/list")
    @ApiOperation(value = "获取店铺列表", notes = "返回json")
    public Result<String> getStoreList(){
        List<StoreListVO> storeListVOList = storeService.getStoreListVOList();
        return ResultGenerator.genSuccessResult(storeListVOList);
    }
}
